home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / bsrc_250.zip / ZSEND.C < prev   
Text File  |  1991-09-15  |  35KB  |  997 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                    Zmodem file transmission module                       */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*    For complete  details  of the licensing restrictions, please refer    */
  17. /*    to the License  agreement,  which  is published in its entirety in    */
  18. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  19. /*                                                                          */
  20. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  21. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  22. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  23. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  24. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  25. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  26. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  27. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  28. /*                                                                          */
  29. /*                                                                          */
  30. /* You can contact Bit Bucket Software Co. at any one of the following      */
  31. /* addresses:                                                               */
  32. /*                                                                          */
  33. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  34. /* P.O. Box 460398                AlterNet 7:491/0                          */
  35. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  36. /*                                Internet f491.n343.z1.fidonet.org         */
  37. /*                                                                          */
  38. /* Please feel free to contact us at any time to share your comments about  */
  39. /* our software and/or licensing policies.                                  */
  40. /*                                                                          */
  41. /*                                                                          */
  42. /*  This module is based largely on a similar module in OPUS-CBCS V1.03b.   */
  43. /*  The original work is (C) Copyright 1986, Wynn Wagner III. The original  */
  44. /*  authors have graciously allowed us to use their code in this work.      */
  45. /*                                                                          */
  46. /*--------------------------------------------------------------------------*/
  47.  
  48. /* Include this file before any other includes or defines! */
  49.  
  50. #include "includes.h"
  51.  
  52. /*--------------------------------------------------------------------------*/
  53. /* Private routines                                                         */
  54. /*--------------------------------------------------------------------------*/
  55.  
  56. void ZS_SendBinaryHeader (unsigned short, byte *);
  57. void ZS_32SendBinaryHeader (unsigned short, byte *);
  58. void ZS_SendData (byte *, int, unsigned short);
  59. void ZS_32SendData (byte *, int, unsigned short);
  60. void ZS_SendByte (byte);
  61. int ZS_GetReceiverInfo (void);
  62. int ZS_SendFile (int, int);
  63. int ZS_SendFileData (int);
  64. int ZS_SyncWithReceiver (int);
  65. void ZS_EndSend (void);
  66.  
  67. /*--------------------------------------------------------------------------*/
  68. /* Private data                                                             */
  69. /*--------------------------------------------------------------------------*/
  70.  
  71. static FILE *Infile;                             /* Handle of file being sent */
  72. static long Strtpos;                             /* Starting byte position of */
  73.                                                  /* download                  */
  74. static long LastZRpos;                           /* Last error location       */
  75. static long ZRPosCount;                          /* ZRPOS repeat count        */
  76. static long Txpos;                               /* Transmitted file position */
  77. static int Rxbuflen;                             /* Receiver's max buffer     */
  78.                                                  /* length                    */
  79. static int Rxflags;                              /* Receiver's flags          */
  80.  
  81. /*--------------------------------------------------------------------------*/
  82. /* SEND ZMODEM (send a file)                                                */
  83. /*   returns TRUE (1) for good xfer, FALSE (0) for bad                      */
  84. /*   sends one file per call; 'fsent' flags start and end of batch          */
  85. /*--------------------------------------------------------------------------*/
  86.  
  87. int Send_Zmodem (char *fname, char *alias, int fsent, int wazoo)
  88. {
  89.    register byte *p;
  90.    register byte *q;
  91.    struct stat f;
  92.    int i;
  93.    int rc = TRUE;
  94.    char j[100];
  95.  
  96. #ifdef DEBUG
  97.    show_debug_name ("send_Zmodem");
  98. #endif
  99.  
  100.    IN_XON_ENABLE ();
  101.  
  102.    z_size = 0;
  103.    Infile = NULL;
  104.  
  105.    if (fname && !(fullscreen && un_attended))
  106.       set_xy ("");
  107.  
  108.    switch (fsent)
  109.       {
  110.       case 0:
  111.          Z_PutString ((byte *)"rz\r");
  112.          Z_PutLongIntoHeader (0L);
  113.          Z_SendHexHeader (ZRQINIT, (byte *)Txhdr);
  114.          /* Fall through */
  115.  
  116.       case NOTHING_TO_DO:
  117.          Rxtimeout = 200;
  118.          if (ZS_GetReceiverInfo () == ERROR)
  119.             {
  120.             XON_DISABLE ();
  121.             XON_ENABLE ();
  122.  
  123.             return FALSE;
  124.             }
  125.       }
  126.  
  127.    Rxtimeout = (int) (614400L / (long) cur_baud.rate_value);
  128.  
  129.    if (Rxtimeout < 100)
  130.       Rxtimeout = 100;
  131.  
  132.    if (fname == NULL)
  133.       goto Done;
  134.  
  135.    /*--------------------------------------------------------------------*/
  136.    /* Prepare the file for transmission.  Just ignore file open errors   */
  137.    /* because there may be other files that can be sent.                 */
  138.    /*--------------------------------------------------------------------*/
  139.    Filename = fname;
  140.    CLEAR_IOERR ();
  141.    if ((Infile = share_fopen (Filename, read_binary, DENY_WRITE)) == NULL)
  142.       {
  143.       (void) got_error (MSG_TXT(M_OPEN_MSG), Filename);
  144.       rc = OK;
  145.       goto Done;
  146.       }
  147.  
  148.    if (isatty (fileno (Infile)))
  149.       {
  150.       errno = 1;
  151.       (void) got_error (MSG_TXT(M_DEVICE_MSG), Filename);
  152.       rc = OK;
  153.       goto Done;
  154.       }
  155.  
  156.  
  157.    /*--------------------------------------------------------------------*/
  158.    /* Send the file                                                      */
  159.    /* Display outbound filename, size, and ETA for sysop                 */
  160.    /*--------------------------------------------------------------------*/
  161.  
  162.    (void) stat (Filename, &f);
  163.  
  164.    i = (int) (f.st_size * 10 / cur_baud.rate_value + 53) / 54;
  165.    (void) sprintf (j, "Z-Send %s, %ldb, %d min.", Filename, f.st_size, i);
  166.    file_length = f.st_size;
  167.  
  168.    if (un_attended && fullscreen)
  169.       {
  170.       clear_filetransfer ();
  171.       sb_move ( file_hWnd, 1, 2);
  172.       FlLnModeSet( FILE_LN_2, 1 );
  173.       sb_puts( GetDlgItem( file_hWnd, FILE_LN_1 ), j );
  174.       elapse_time ();
  175.       (void